import { Component } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { LocalStorageService } from './services/local-storage-v2/local-storage.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = '选课系统';

  constructor(public router: Router, private ls2: LocalStorageService) {
    // 解决从 / 访问，但是由于存储问题，菜单项停留在旧状态，与实际状态页面不符的问题
    this.router.events.subscribe(event => {
      if (event instanceof NavigationStart) {
        if ('/' === event.url) {
          this.ls2.set('menu.selected', {
            待选课程: true,
            已选课程: false
          });
        }
      }
    });
  }
}
